<%--
 $Author: wangchw $
 $Rev: 50763 $
 $Date:: 2015-07-15 17:22:44#$:

 Copyright (C) 2012 Seeyon, Inc. All rights reserved.
 This software is the proprietary information of Seeyon, Inc.
 Use is subject to license terms.
--%>
<%@ page contentType="text/html; charset=utf-8" isELIgnored="false"%>
<%@ page import="com.seeyon.ctp.common.constants.LoginConstants"%>
<%@ page isELIgnored="false" import="com.seeyon.ctp.common.AppContext,java.util.Locale"%>
<%@ page isELIgnored="false" import="com.seeyon.ctp.util.json.JSONUtil,java.util.Locale"%>
<%@ page isELIgnored="false" import="com.seeyon.ctp.common.constants.ProductEditionEnum,java.util.Locale"%>
<%@ taglib uri="http://v3x.seeyon.com/taglib/core" prefix="v3x"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
<%@ taglib prefix="ctp" uri="http://www.seeyon.com/ctp"%>
<%

    response.setHeader("Pragma", "No-cache");
    response.setHeader("Cache-Control", "no-store");
    response.setDateHeader("Expires", 0);
    boolean isDevelop = AppContext.isRunningModeDevelop();
	String ctxPath =request.getContextPath(),  ctxServer = request.getScheme()+"://" + com.seeyon.ctp.util.Strings.getServerName(request) + ":"
        + request.getServerPort() + ctxPath;
    Locale locale = AppContext.getLocale();
    String editorNames = AppContext.getSystemProperty("editor.FontNames");


%>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="renderer" content="webkit|ie-stand|ie-comp" />
<meta HTTP-EQUIV="pragma" CONTENT="no-cache" />
<meta HTTP-EQUIV="Cache-Control" CONTENT="no-store, must-revalidate" />
<meta HTTP-EQUIV="expires" CONTENT="0" />
<title>${loginTitleName}</title>
<link rel="stylesheet" href="/seeyon/common/all-min.css${ctp:resSuffix()}">
<link rel="stylesheet" href="/seeyon/skin/dist/components/components_layout.css${ctp:resSuffix()}">
<link rel="stylesheet" href="/seeyon/skin/dist/components/components_theme_default.css${ctp:resSuffix()}">
<c:set var="path" value="${pageContext.request.contextPath}" />
<script type="text/javascript">
	var CSRFTOKEN = '<%=session.getAttribute("CSRFTOKEN")%>';
	var _ctxPath = '<%=ctxPath%>', _ctxServer = '<%=ctxServer%>';
	var _locale = '<%=locale%>',_isDevelop = <%=isDevelop%>,_sessionid = '<%=session.getId()%>',_isModalDialog = false;
	var _editionI18nSuffix = '<%=ProductEditionEnum.getCurrentProductEditionEnum().getI18nSuffix()%>';
	<c:if test="${param._isModalDialog == 'true' || param.isFromModel == 'true'}">
	_isModalDialog = true;
	</c:if>
	var _resourceCode = "${ctp:escapeJavascript(param._resourceCode)}";
	var seeyonProductId="${ctp:getSystemProperty("system.ProductId")}";
    <%if("true".equals(request.getAttribute("editor.enabled"))){%>
    var systemfileUploadmaxsize="${ctp:getSystemProperty("fileUpload.image.maxSize")}";
    var _fontNames = '<%=editorNames%>';
    <%}%>
</script>
<%
    if (isDevelop) {
%>

<script type="text/javascript" src="${path}/common/js/ui/calendar/calendar-debug.js"></script>
<script type="text/javascript" src="${path}/common/js/jquery-debug.js"></script>
<script type="text/javascript" src="${path}/common/js/misc/Moo-debug.js"></script>
<script type="text/javascript" src="${path}/common/js/misc/jsonGateway-debug.js"></script>
<script type="text/javascript" src="${path}/common/js/jquery.json-debug.js"></script>
<script type="text/javascript" src="${path}/common/js/jquery.fillform-debug.js"></script>
<script type="text/javascript" src="${path}/common/js/jquery.jsonsubmit-debug.js"></script>
<script type="text/javascript" src="${path}/common/js/jquery.hotkeys-debug.js"></script>
<script type="text/javascript" src="${path}/common/js/jquery.ajaxgridbar-debug.js"></script>
<script type="text/javascript" src="${path}/common/js/jquery.code-debug.js"></script>
<script type="text/javascript" src="${path}/common/js/common-debug.js"></script>
<script type="text/javascript" src="${path}/common/js/v3x-debug.js"></script>
<script type="text/javascript" src="${path}/common/js/seeyon.ui.core-debug.js"></script>
<script type="text/javascript" src="${path}/common/js/jquery.comp.lbs-debug.js"></script>
<!--seeyonUI start-->
<script type="text/javascript" src="${path}/common/js/ui/searchBox-debug.js"></script>
<script type="text/javascript" src="${path}/common/js/ui/seeyon.ui.calendar-debug.js"></script>
<script type="text/javascript" src="${path}/common/js/ui/seeyon.ui.checkform-debug.js"></script>
<script type="text/javascript" src="${path}/common/js/ui/seeyon.ui.colorPanel-debug.js"></script>
<script type="text/javascript" src="${path}/common/js/ui/seeyon.ui.common-debug.js"></script>
<script type="text/javascript" src="${path}/common/js/ui/seeyon.ui.dialog-debug.js"></script>
<script type="text/javascript" src="${path}/common/js/ui/seeyon.ui.grid-debug.js"></script>
<script type="text/javascript" src="${path}/common/js/ui/seeyon.ui.layout-debug.js"></script>
<script type="text/javascript" src="${path}/common/js/ui/seeyon.ui.menu-debug.js"></script>
<script type="text/javascript" src="${path}/common/js/ui/seeyon.ui.peopleCrad-debug.js"></script>
<script type="text/javascript" src="${path}/common/js/ui/seeyon.ui.print-debug.js"></script>
<script type="text/javascript" src="${path}/common/js/ui/seeyon.ui.progress-debug.js"></script>
<script type="text/javascript" src="${path}/common/js/ui/seeyon.ui.shortCutSet-debug.js"></script>
<script type="text/javascript" src="${path}/common/js/ui/seeyon.ui.tab-debug.js"></script>
<script type="text/javascript" src="${path}/common/js/ui/seeyon.ui.toolbar-debug.js"></script>
<script type="text/javascript" src="${path}/common/js/ui/seeyon.ui.tooltip-debug.js"></script>
<script type="text/javascript" src="${path}/common/js/ui/seeyon.ui.tree-debug.js"></script>
<!--seeyonUI end-->
<script type="text/javascript" src="${path}/common/js/jquery.comp-debug.js"></script>
<script type="text/javascript" src="${path}/common/js/jquery.tree-debug.js"></script>
<script type="text/javascript" src="${path}/common/js/jquery.autocomplete-debug.js"></script>
<script type="text/javascript" src="${path}/common/js/jquery.dd-debug.js"></script>
<%
    } else {
%>
<script type="text/javascript" src="${path}/common/all-min.js${ctp:resSuffix()}"></script>
<%
    }
%>
<script type="text/javascript" src="/seeyon/ajaxStub.js?v=<%=com.seeyon.ctp.common.SystemEnvironment.getServerStartTime()%>"></script>
<c:set var="loginTime" value="${ CurrentUser !=null ? CurrentUser.etagRandom : 0}" />
<c:set var="path" value="${pageContext.request.contextPath}" />
<c:if test="${loginFrom!='loginPortal'}">
<link href="/seeyon/common/images/${ctp:getSystemProperty('portal.porletSelectorFlag')}/favicon${ctp:getSystemProperty('portal.favicon')}.ico" type="image/x-icon" rel="icon"/>
</c:if>
<c:if test="${_SecuritySeed != null}">
<script type="text/javascript" src="/seeyon/common/js/crypto.js${ctp:resSuffix()}"></script>
</c:if>
<script type="text/javascript" src="/seeyon/main/common/js/jquery.qrcode.min.js${ctp:resSuffix()}"></script>
<script type="text/javascript" src="/seeyon/main/common/js/qrcode-uuid.js${ctp:resSuffix()}"></script>
<c:if test="${adSSOEnable}">
<%
if(request.getHeader("authorization")==null) {
  response.setStatus(401);
  response.setHeader("Cache-Control", "no-store");
  response.setDateHeader("Expires", 0L);
  response.addHeader("WWW-Authenticate", "Negotiate");
}
%>
</c:if>
<script type="text/javascript">

	var loginFrom= '${ctp:escapeJavascript(loginFrom)}';
	var interval;
	var sendFlag = false;

	var _SecuritySeed = '${_SecuritySeed}';
	var _SecuritySeedTimeOut='${_SecuritySeedTimeOut}';

	var adjustMarginTop;
	var isIE8 = (navigator.userAgent.indexOf("MSIE") >= 0 || navigator.userAgent.indexOf("Trident") >= 0) &&  /msie 8\.0/i.test(navigator.userAgent) || (navigator.userAgent.indexOf("MSIE") >= 0 || navigator.userAgent.indexOf("Trident") >= 0) && /msie 7\.0/i.test(navigator.userAgent);

	var ajaxQrCodeLoginManager = new qrCodeLoginManager();
	function loginForWechat(){
		var random = $("#random").val();
		ajaxQrCodeLoginManager.isLogin(random,{
			success : function(data) {
				if(data != "loginError" || data == null){
					$("#login_username").val(data);
					$("#login_button").click();
				} else {
					sendFlag = true;
				}
			}
		});
	}

	//轮询请求，防止后台阻塞
	function intervalLogin(){
		if(sendFlag){
			sendFlag = false;
			loginForWechat();
		}
	}

	//二维码登陆
	function changeLoginMode (_layout) {
		var adjustWidth = 171;
		var adjustHeight = 171;
		$(".qrCodeBtn,.qrcodeAreaLogin").click(function () {
			showQrcodeArea();
			var date = new Date();
			var dateNumber = date.getTime();
			var random="seeyon-" + Math.uuid() + "-" + dateNumber;
			var qrcodeRandom = "https://weixin.seeyon.com/mobilehelp.jsp?random=" + random;
			$("#random").val(random);
			//canvas方式进行图片渲染
			$("#qrcode1 .qrcode").empty();
	        $("#qrcode1 .qrcode").qrcode({
	            render: isIE8?"table":"canvas", //canvas方式
	            width: adjustWidth, //宽度
	            height: adjustHeight, //高度
	            text: utf16to8(qrcodeRandom) //任意内容
	        });
			loginForWechat();
			interval = setInterval("intervalLogin()", 1000);
		});
		$("#flashQrcode").click(function(){
			$("#qrcode1 .qrcode").empty();
			var date = new Date();
			var dateNumber = date.getTime();
			var random="seeyon-" + Math.uuid() + "-" + dateNumber;
			var qrcodeRandom = "https://weixin.seeyon.com/mobilehelp.jsp?random=" + random;
			$("#random").val(random);
			//canvas方式进行图片渲染
            $("#qrcode1 .qrcode").qrcode({
                render: isIE8?"table":"canvas", //canvas方式
                width: adjustWidth, //宽度
                height: adjustHeight, //高度
                text: utf16to8(qrcodeRandom) //任意内容
            });
        	<c:if test="${ctp:getSysFlagByName('sys_isGovVer') and ctp:hasPlugin('trustdo')}">
        		freshLoginQRCodeForMobileShield();
        	</c:if>
		});
	}

	//识别中文，暂时未用，目前随机数不包含中文
	function utf16to8(str) {
        var out, i, len, c;
        out = "";
        len = str.length;
        for (i = 0; i < len; i++) {
            c = str.charCodeAt(i);
            if ((c >= 0x0001) && (c <= 0x007F)) {
                out += str.charAt(i);
            } else if (c > 0x07FF) {
                out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
                out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
                out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
            } else {
                out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
                out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
            }
        }
        return out;
    }

	//NC Portal
	try{
		if(parent.frame_A8){
			if("${ctp:hasPlugin('nc')}" == "true"){
			   var ncPortalUrl = "${ctp:getSystemProperty('nc.portal.url')}";
			   var ncUrl= "${ctp:getSystemProperty('nc.server.url.prefix')}";
			   if(ncPortalUrl!=null&&ncPortalUrl!=''){
			      window.location.href = ncPortalUrl+"/portal/logoutA8.jsp";
			   }else{
			     window.location.href = ncUrl+"/portal/logoutA8.jsp";
			   }
			}
		}
	}catch(e){}
	function onLoginSubmit(){
		//登陆请求发出后，按钮置灰
	      $("#login_button").attr("disabled","disabled");
	      //var _bodyWidth = document.documentElement.clientWidth;
	      //var _bodyHeight = document.documentElement.clientHeight;
	      var _screenWidth = window.screen.width;
	      var _screenHeight = window.screen.height;
	      var font_size = 12;

	      /*if(_bodyWidth <= 1024){
	    	  font_size = 12;
	      }else if(_bodyWidth <= 1600){
	    	  font_size = 14;
	      }else if(_bodyWidth <= 2500){
	    	  font_size = 16;
	      }else{
	    	  font_size = 18;
	      }*/

	      $("#login_form").append("<input type='hidden' name='fontSize' value='"+font_size+"' />").append("<input type='hidden' name='screenWidth' value='"+_screenWidth+"' />").append("<input type='hidden' name='screenHeight' value='"+_screenHeight+"' />");
	      <c:if test="${_SecuritySeed != null}">
	      var us = CryptoJS.enc.Utf8.parse($("#login_password").val());
	      var encrypted = CryptoJS.DES.encrypt(us, _SecuritySeed);
	      $("#login_password").val(encrypted);
	      </c:if>
	      var loginFlag = true;
	      if(loginCallback) {
	        if(!loginCallback())
	          loginFlag = false;
	      }
	      var hasPluginCA = "${hasPluginCA}";
	      var caFactory = '${caFactory}';
	      if(hasPluginCA == "true" &&caFactory!=''){
	        if("koal"!="${caFactory}" && isCa){
	          caSign();
	        }
	      }
	      ${activeXLoader};
	      return loginFlag;
	}
  $.ctx.template = <c:out value="${templatesJsonStr}" default="null" escapeXml="false"/>;
  $.ctx.hotSpots = <c:out value="${hotSpotsJsonStr}" default="null" escapeXml="false"/>;
  var loginResult = "${sessionScope['login.result']}";
  var dueRemind = "${dueRemind}";
  var dueRemindV = "${dueRemindV}";
  $(function() {
	  $("#login_form").append("<input type='hidden' name='random' id='random' value='' />");
	  <c:if test="${_SecuritySeed != null}">
      //开启前端加密以后，不允许自动保存密码
      $("#login_password").attr("autocomplete","off");
      $("#login_username").val("");
      $("#login_password").val("");
      </c:if>
    if(loginResult){
      $("#login_error").find("div").html(loginResult);
      $("#login_error").show();
    }else{
      $("#login_error").hide();
    }
    if(seeyonProductId == 7){
      //如果是a6s
      var localeCfg = [{"eleid":"login_locale","defaultValue":"zh_CN","options":{"zh_CN":"中文（简体）"}}];
    } else {
      var localeCfg = <c:out value="${locales}" default="null" escapeXml="false"/>;
      if(seeyonProductId == 3 || seeyonProductId == 4){
          delete localeCfg[0].options.en;
      }
    }
    $.fillOption(localeCfg);

/**
    $("#login_locale").change(function() {
      $("#login_locale").jsonSubmit({
        action : _ctxPath + '/main.do?method=changeLocale'
      });
    });**/

    var _dropdownObj =$.dropdown({
          id:'login_locale',
          onchange:function(){
        	  if(loginFrom && loginFrom!=''){
        		  $("#login_locale").jsonSubmit({
                	  action : _ctxPath + '/main.do?method=changeLocale&loginFrom=${ctp:escapeJavascript(loginFrom)}&topValue=${ctp:escapeJavascript(param.topValue)}&rowList='+encodeURIComponent(rowList)+'&btnbgc='+encodeURIComponent(btnbgc)+'&btombgc='+encodeURIComponent(btombgc)+'&bgc='+encodeURIComponent(bgc)+'&${ctp:escapeJavascript(mailParam)}'
                  });
        	  }else{
        		  $("#login_locale").jsonSubmit({
                	  action : _ctxPath + '/main.do?method=changeLocale&${ctp:escapeJavascript(mailParam)}'
                  });
        	  }
          }
    });
    _dropdownObj.setValue(_locale);

    $("#login_form").submit(function() {
		var loginFlag = onLoginSubmit();
      	return loginFlag;
    });

    $("#login_password").keydown(function(event){
    	if (event.keyCode==13) {
    		loginButtonClick();
		}
    });
    var submitCount= 0;
    function loginButtonClick(){
    	if(submitCount==0){
    		submitCount ++;
    		$("#login_button").click();
    	}
    }

    var enterSubmit = true;
    $("#login_username").keydown(function(event){
      if(event.keyCode == 229) return;
      if(event.keyCode == 40)
        enterSubmit = false;
		  if (event.keyCode==13) {
		    if(enterSubmit)
		    	{
			    	 //针对password在首次按enter键提交无法获取值的情况进行特殊处理,支艳强，2016/05/04
			    	 //弹出一个progressBar,强制刷新DOM,浏览器会把password的内容展示出来
		    	     var login_password = $("#login_password").val();
			         if ($.trim(login_password) == "")
			        	 {
				        	 var progress = $.progressBar();
				        	 window.setTimeout(function(){
				        		 progress.close();

				        		 loginButtonClick();
				        	 },100);
			        	 }
			         else
			        	 {
			        	 	loginButtonClick();
			        	 }
		    	}
		    else
		      enterSubmit = true;
		  }
    });

    $("#login_button").keydown(function(event){
    	if (event.keyCode==13) {
    		loginButtonClick();
		}
    });
    $("#VerifyCode").keydown(function(event){
      if (event.keyCode==13) {
    	  loginButtonClick();
      }
  	});
    if("true" == "${hasPluginCA}" && "Jit" == "${caFactory}"){
    	$("#login_form").append("<input type='hidden' id='signed_data' name='signed_data' value=''>")
			    		.append("<input type='hidden' id='original_jsp' name='original_jsp' value=''>")
			    		.append("<input type='hidden' id='RootCADN' name='RootCADN' value=''>");
    }
  });
</script>